<?php

/**
 * 首页控制器
 */
namespace Custom\Controller;
use Think\Controller;

class CompanyController extends UserController
{

    function __construct()
    {
        parent::__construct();
        $this->M_company = M('Company');
    }

    public function index()
    {
        $info = $this->M_company->find($this->c_id);
        if (IS_POST) {
            $upload = new \Think\Upload();
            $upload->maxSize = 3145728;
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
            $upload->rootPath = './';
            $upload->savePath = './Uploads/' . $this->c_id . '/logo/' . $this->uid . '/';
            $img_info = $upload->upload();
            if ($img_info) {
                $company_logo = $img_info['company_logo']['savepath'] . $img_info['company_logo']['savename'];
                $this->M_company->company_logo = $company_logo;
                session('company_logo', $company_logo);
            }
            $this->M_company->company_name = I('post.company_name');
            session('company_name', I('post.company_name'));
            $this->M_company->full_name = I('post.full_name');
            $this->M_company->tel = I('post.tel');
            if ($this->M_company->save()) {
                die($this->success(L("edsuccess"), U('goods/index')));
            } else {
                die($this->error(L("edfailed")));
            }
        }
        $this->assign('info', $info);
        $this->display();
    }
}